import { axios } from '@/utils/request'
import baseapi from '@/api/base'

const api = {
  orgserver: '/org',
  orgList: '/',
  orgCount: '/count/',
  // orgInfo: '/'
  findByIdno: '/org/byIdno'
}

export default api

export function getOrgList (parameter, headers) {
  const allheaders = {
    appId: baseapi.huiwcore_app
  }
  return axios({
    url: baseapi.baseUrl + baseapi.huiwcore + api.orgserver + api.orgList,
    method: 'get',
    headers: Object.assign(headers, allheaders),
    params: parameter
  })
}

export function getOrgCount (parameter, headers) {
  const allheaders = {
    appId: baseapi.huiwcore_app
  }
  return axios({
    url: baseapi.baseUrl + baseapi.huiwcore + api.orgserver + api.orgCount,
    method: 'get',
    headers: Object.assign(headers, allheaders)
  })
}

export function getOrgInfoByPid (parameter, headers) {
  const allheaders = {
    appId: baseapi.huiwcore_app
  }
  return axios({
    url: baseapi.baseUrl + baseapi.huiwcore + api.orgserver + '/' + parameter,
    headers: Object.assign(headers, allheaders),
    method: 'get'
    // params: parameter
  })
}

export function getOrgInfoByIdno (parameter, headers) {
  console.log(parameter)
  const allheaders = {
    appId: baseapi.huiwcore_app
  }
  return axios({
    url: baseapi.baseUrl + baseapi.huiwcore + api.findByIdno + '/' + parameter,
    headers: Object.assign(headers, allheaders),
    method: 'get'
    // params: parameter
  })
}

// id == 0 add     post
// id != 0 update  put
export function saveOrgInfo (parameter, headers) {
  const allheaders = {
    appId: baseapi.huiwcore_app
  }
  return axios({
    url: baseapi.baseUrl + baseapi.huiwcore + api.orgserver + '/',
    method: parameter.sysSeq === 0 ? 'post' : 'put',
    headers: Object.assign(headers, allheaders),
    data: parameter
  })
}
